<layout name='layout' />
<style>
.mBox{clear: both; overflow: hidden;}
.cName{float: left; width: 110px; text-align: right; box-sizing: border-box; padding-right: 15px}
.cx{ margin-left: 110px; overflow: hidden;}
.cx li{margin-bottom: 10px; border: 1px #ddd solid; font-size: 12px; padding: 5px; float: left; margin-right: 10px; white-space: normal; cursor: pointer;}
.cx li.active{background-color: #f60; color: #fff; border-color: #f60}
</style>
<div class="admin-main">
		<blockquote class="layui-elem-quote">
		<a href="<{:U('Goods/index')}>" class="layui-btn layui-btn-small">
			<i class="layui-icon">&#xe608;</i> 返回列表
		</a>
	</blockquote>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		<legend>编辑</legend>
	</fieldset>

	<form id="ajaxForm" class="layui-form" method="post" action="<{:U('Goods/edit')}>">
		<div class="layui-form-item">
			<label class="layui-form-label">名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" value="<{$list.name}>" lay-verify="required" placeholder="请输入商品名称" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">分类</label>
			<div class="layui-input-block">
				<select name="cid" id="cid" lay-verify="required">
		    	<option value="">==请选择==</option>
		        <volist name="cate" id="vo">
		        <option value="<{$vo['id']}>,<{$vo['path']}>"><php>
		            for($i=0; $i<$vo['count']*2; $i++){
		               echo '&nbsp;&nbsp;';            
		            }
		        </php><{$vo['name']}></option>
		        </volist>
		        </select>
			</div>
		</div>

		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">规格</label>
			<div class="layui-input-block">
				<textarea name="texing" class="layui-textarea" lay-verify="required"><{$list.texing}></textarea>
			</div>
		</div>

		<div class="mBox">
			<div class="cName">适用品牌</div>
			<div class="cx" id="brand">
	        	<volist name="c_data.brand" id="vo">
				<li data-id="<{$vo.id}>" <php>if(in_array($vo['id'],$brandID)) echo 'class="active"';</php>><{$vo.name}></li>
				</volist>
			</div>
		</div>
		
		<div class="mBox">
			<div class="cName">适用车型</div>
			<div class="cx" id="car">
				<volist name="car" id="vo">
				<li data-id="<{$vo.id}>" <php>if(in_array($vo['id'],$carID)) echo 'class="active"';</php>><{$vo.carName}></li>
				</volist>
			</div>
		</div>
		<input type="hidden" name="brandID" id="brandID" value="<{$list.brandID}>">
		<input type="hidden" name="carID" id="carID" value="<{$list.carID}>">

		<div class="layui-form-item">
			<label class="layui-form-label">产品图片</label>
			<div class="layui-inline">
				<div class="insert-img">
					<volist name="list.image" id="vo">
					<li><img src="<{$vo}>" /><input type="hidden" name="image[]" value="<{$vo}>" /><i class="fa fa-close" onclick="removeLi(this)"></i><a <eq name="vo" value="$list.face">class="active"</eq> href="javascript:void(0)" onclick="setFace(this,'face','<{$vo}>')">设为封面</a></li>
					</volist>
					<a href="javascript:;" onclick="uploadMultiFile('<{:U('Upload/image')}>','picname');" class="insert-btn">+</a>
				</div>						
			</div>
			<input type="hidden" name="face" id="face" value="<{$list.face}>">
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">状态</label>
			<div class="layui-input-inline">
				<input type="radio" name="show" value="1" title="显示" <php>if($list['show']==='1')echo checked;</php>>
				<input type="radio" name="show" value="0" title="隐藏" <php>if($list['show']==='0')echo checked;</php>>
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">首页推荐</label>
			<div class="layui-input-inline">
				<input type="radio" name="index" value="1" title="是" <php>if($list['index']==='1')echo checked;</php>>
				<input type="radio" name="index" value="0" title="否" <php>if($list['index']==='0')echo checked;</php>>
			</div>
		</div>


		<div class="layui-form-item">
			<label class="layui-form-label">排序</label>
			<div class="layui-input-inline">
				<input type="text" name="sort" id="sort" value="<{$list['sort']}>" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">介绍</label>
			<div class="layui-input-block">
				<textarea name="content" id="container" lay-verify="content"><{$list['content']}></textarea>
				<script type="text/javascript" src="<{:C('UE_DIR')}>/my.config.js"></script>
				<script type="text/javascript" src="<{:C('UE_DIR')}>/ueditor.all.js"></script>
				<script type="text/javascript" src="<{:C('UE_DIR')}>/lang/zh-cn/zh-cn.js"></script>
				<script type="text/javascript">
				var defPath = "<{:C('UPLOAD_PATH')}>";
				window.UEDITOR_CONFIG.imagePath= defPath;  //插入编辑器中图片路径修正
				window.UEDITOR_CONFIG.filePath= defPath; //插入编辑器中文件路径修正
				window.UEDITOR_CONFIG.scrawlPath= defPath; //涂鸦默认路径
				var editor = UE.getEditor('container');
				</script>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
				<button type="button" class="layui-btn layui-btn-primary" onclick="window.history.go(-1)">返回</button>
			</div>
		</div>
		<input type="hidden" name="id" value="<{$list['id']}>" />
	</form>
</div>
<script>
function selectToString(obj,symbol){
	var symbol=symbol||','; 
	var str = '';
	obj.each(function(index){
		if (index==0){
			str = $(this).attr("data-id");
		}else{
			str += symbol+$(this).attr("data-id");
		}
	});
	return str;
}

$("#cid").val("<{$list['cid']}>,<{$list['path']}>");

$(function(){

	$("#brand li").click(function(){
		if ($(this).hasClass("active")) {
			$(this).removeClass("active");
		}else{
			$(this).addClass("active");
		}	
		var brand = $("#brand li.active");
		brandID = selectToString(brand);
		$("#brandID").val(brandID);
		$("#carID").val('');

		var load = layer.load(0,{shade: [0.3, '#000000']});
		$.ajax({
			url : '<{:U('Goods/getChexing')}>',
			dataType : 'json',
			type : 'post',
			data : {bid:brandID},
			success : function(r){
				layer.close(load);
				if (r.status==0) {					
					layer.msg('读取失败');
				}else{
					_html = '';
					$.each(r.data,function(index,o){
                            _html += '<li data-id="'+o.id+'">'+o.carName+'</li>';
                        })
					$("#car").html(_html);
				}
			}
		});
	});

	$(document).on('click','#car li',function(){
		if ($(this).hasClass("active")) {
			$(this).removeClass("active");
		}else{
			$(this).addClass("active");
		}	
		var car = $("#car li.active");
		carID = selectToString(car);
		$("#carID").val(carID);
	});
})
</script>

<!--上传文件-->
<form style="display:none;" id='myupload' action="" method='post' enctype='multipart/form-data'>
<input id="fileupload" type="file" name="file">
</form>
<div id="uploading" style="display:none;">
	<div class="wrapper">
		<div class="load-bar">   
			<div class="load-bar-inner" data-loading="0"> <span id="counter">0%</span> </div> 
		</div>  
		<p>请等待... </p>
	</div>
</div>